package com.libraryManage.controller;

import cn.hutool.json.JSONObject;
import com.libraryManage.commons.utils.MVCUtil;
import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.entity.BookHomeDo;
import com.libraryManage.entity.HomePageDo;
import com.libraryManage.entity.ManagerDo;
import com.libraryManage.service.HomePageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Controller
@Slf4j
@RequestMapping("/lib")
public class indexController {

    @Autowired
    HomePageService homePageService;

    @RequestMapping(value = "/index" , method = RequestMethod.GET)
    public String libRoom(){
        return "书房首页";
    }

    @RequestMapping(value = "/in" , method = RequestMethod.GET)
    public String libout(){
        return "登录";
    }

    @RequestMapping(value = "/test" , method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<List<BookHomeDo>> testInterface(HttpServletRequest request, @CookieValue("userId") String userId){
        System.out.println(userId);
        return homePageService.getBookData();
    }

    @RequestMapping(value = "/login" , method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity<ManagerDo> login(ManagerDo managerDo){
        return homePageService.getUserData(managerDo);
    }

}
